#include "ButtonPad.h"
#include <QGridLayout>

ButtonPad::ButtonPad(QWidget *parent) : QWidget(parent)
{
    QGridLayout *layout = new QGridLayout(this);

    for(int row = 0; row < ROW; row++)
    {
        for(int col = 0; col < COL; col++)
        {
            m_table[row][col] = new QPushButton(this);
            m_table[row][col]->setText(QString("%1x%2").arg(row+1).arg(col+1));
            m_table[row][col]->setCheckable(true);
            layout->addWidget(m_table[row][col], row, col, Qt::AlignCenter);
        }
    }
    m_table[0][0]->setChecked(true);
    setLayout(layout);
}

QVector<QPoint> ButtonPad::getChecked()
{
    QVector<QPoint> vect;
    for(int row = 0; row < ROW; row++)
    {
        for(int col = 0; col < COL; col++)
        {
            if(m_table[row][col]->isChecked())
            {
                vect.push_back(QPoint(row, col));
            }
        }
    }
    return vect;
}

void ButtonPad::uncheckAll(void)
{
    for(int row = 0; row < ROW; row++)
    {
        for(int col = 0; col < COL; col++)
        {
            m_table[row][col]->setChecked(false);
        }
    }
}

void ButtonPad::checkAll(void)
{
    for(int row = 0; row < ROW; row++)
    {
        for(int col = 0; col < COL; col++)
        {
            m_table[row][col]->setChecked(true);
        }
    }
}

ButtonPad::~ButtonPad()
{

}

